/*
解题思路：给所有同学的时间按从小到大排个序，也就是s+a+e的排序
排序完后即是发消息的时刻之和最小
*/
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e3 + 10;
typedef long long ll;
struct Value {
    int s;
    int a;
    int e;
    ll total;
    bool operator<(const Value &p)const{
        /*if (p.total == this->total)
            return p.s + p.a>this->s + this->a;*/
        return p.total>this->total;
    }
};
Value V[N];
int n;
int main(){
    cin >> n;
    for (int i = 0; i < n; i++) {
        int s,a,e;
        cin >> s >> a >> e;
        V[i].a = a, V[i].s = s, V[i].e = e;
        V[i].total = a + s + e;
    }
    sort(V,V+n);
    ll ans = 0, temp = 0;;
    for (int i = 0; i < n; i++) {
        ans+=temp + V[i].s + V[i].a;
        temp+= V[i].total;
        /*cout << "s:"<<V[i].s<<" "<<"a:"<<V[i].a<<" " 
            <<"e:"<<V[i].e<< endl;*/
    }
    cout << ans << endl;

    return 0;

}